import React from 'react'
import { Link } from 'react-router-dom'
import classNames from 'classnames'
import './index.scss';

export default (props) => {
  let { text, to, children, className, onClick, disabled } = props;
  let classname = classNames(
    'link',
    className,
    { disabled }
  );

  if (disabled) {
    return (
      <span className={classname} onClick={(e) => onClick && onClick(e)}>
        {text}
        {children}
      </span>
    );
  }

  return (
    /^(http|https|\/\/)/.test(to) ?
      <a className={classname} href={to} onClick={(e) => onClick && onClick(e)}>
        {text}
        {children}
      </a> :
      <Link className={classname} to={to} onClick={(e) => onClick && onClick(e)}>
        {text}
        {children}
      </Link>
  );
}
